/*
 * @Description:
 * @Version: 1.0.0
 * @Autor: Ceart <1871321876@qq.com>
 * @Date: 2022-08-04 21:27:42
 * @LastEditors: Ceart
 * @LastEditTime: 2022-08-05 20:02:20
 */
import Chalk from 'chalk';
import moment from 'moment';

export const chalk = Chalk;
export const chalkINFO = (v) =>
  `${chalk.bgBlueBright.black(' INFO ')} ${chalk.blueBright(v)}`;
export const chalkSUCCESS = (v) =>
  `${chalk.bgGreenBright.black(' SUCCESS ')} ${chalk.greenBright(v)}`;
export const chalkERROR = (v) =>
  `${chalk.bgRedBright.black(' ERROR ')} ${chalk.redBright(v)}`;
export const chalkWRAN = (v) =>
  `${chalk.bgHex('#FFA500').black(' WRAN ')} ${chalk.hex('#FFA500')(v)}`;

const cLog = console.log;
const cError = console.error;

const chalkTextWord = chalk.inverse.bold('$1');
const chalkTextValue = chalk.white('[$1]');

const colorful = function (str) {
  return str
    .replace(/\[(.*?)\]/g, chalkTextWord)
    .replace(/\{(.*?)\}/g, chalkTextValue);
};

global.L = function () {
  if (arguments.length) {
    const time = moment().format('YY-MM-DD HH:mm:ss.SSS');
    const args: any = [];

    for (let i: number = 0; i < arguments.length; i += 1) {
      args[i] = arguments[i];
    }
    const str = chalk.green(`[${time}][信息]: ${colorful(args.join('\n'))}`);

    cLog(str);
  } else {
    console.log();
  }
};

global.LE = function () {
  if (arguments.length) {
    const time = moment().format('YY-MM-DD HH:mm:ss.SSS');
    const args: any = [];

    for (let i: number = 0; i < arguments.length; i += 1) {
      args[i] = arguments[i];
    }

    const str = chalk.yellow(`[${time}][错误]: ${colorful(args.join('\n'))}`);

    cError(str);
  } else {
    console.log();
  }
};
